// pages/drivedetail/drivedetail.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    info:[],
    shop_id:0,
    chang_num:0,
    class_num:0,
    changdi:[],
    classList:[],
    phone:''
  },
  todrivemassage:function(e){
    var shop_id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: "../drivemassage/drivemassage?shop_id="+shop_id,
      success: function (res) {
        // success
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })
  },
  
  todrivePlace: function (e) {
    var shop_id = e.currentTarget.dataset.shopid;
    wx.navigateTo({
      url: "../driveplace/driveplace?shop_id="+shop_id,
      success: function (res) {
        // success
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })
  },
  toallClass:function(e){
    var shop_id = e.currentTarget.dataset.shopid;
    wx.navigateTo({
      url: "../classList/classList?shop_id="+shop_id,
      success: function (res) {
        // success
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })
  },
  toclassdetail:function(e){
    var class_id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: "../classdetail/classdetail?class_id="+class_id,
      success: function (res) {
        // success
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })
  },
  toconsulting:function(){
    wx.navigateTo({
      url: "../consulting/consulting",
      success: function (res) {
        // success
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })
  },
  tocall: function () {
    var that = this;
    wx.showModal({
      title: '提示',
      content: '您是否要电话咨询？',
      success: function (res) {
        if (res.confirm) {
          // 此时是打电话咨询
          wx.makePhoneCall({
            phoneNumber: that.data.info.tel,
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var shop_id = options.shop_id;
    var that = this;
    that.setData({
      shop_id : shop_id
    });
    wx.request({
      url: app.d.ceshiUrl + '/Api/Shangchang/detail',
      method: 'post',
      data: {
        shop_id: shop_id
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        if(res.data.status == 1){
          console.log(res)
          that.setData({
            info: res.data.info,
            chang_num: res.data.chang_num,
            class_num: res.data.class_num,
            changdi: res.data.changdi,
            classList: res.data.classList,
            phone:res.data.phone 
          });
        }else{
          wx.showToast({
            title: res.data.err,
          })
        }
        
        //endInitData
      },
      fail: function (e) {
        wx.showToast({
          title: '网络异常！',
          duration: 2000
        });
      },
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})